package com.hubstc.book_borrow.controller;

import com.hubstc.book_borrow.pojo.Result;
import com.hubstc.book_borrow.pojo.Category;
import com.hubstc.book_borrow.service.BookCategoryService;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/bookCategory")
public class BookCategoryController {

    @Resource
    private BookCategoryService bookCategoryService;

    @PostMapping("/addCategory")
    public Result addCategory(@RequestBody Category category){
        bookCategoryService.addCategory(category);
        return Result.success();
    }

        @GetMapping("/getCategoryList")
    public Result getCategoryList(){
        return Result.success(bookCategoryService.findAllCategory());
    }

    @GetMapping("/findCategoryById")
    public Result findCategoryById(int id){
        return Result.success(bookCategoryService.findCategoryById(id));
    }

    @PutMapping("/update")
    public Result updateCategory(@RequestBody Category category){
        bookCategoryService.updateCategory(category);
        return Result.success();
    }

    @DeleteMapping("/delete")
    public Result deleteCategory(int categoryId){
        bookCategoryService.deleteCategory(categoryId);
        return Result.success();
    }
}
